package com.java.demo.demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @auther zhangwj
 * @date 2020/9/16 2:11 下午
 */
public class Demo1 {

    public static void main(String[] args) {
        Random random1 = new Random(1);
        Random random2 = new Random(2);
        System.out.println(random1.nextDouble() + "-----" + random2.nextDouble());
    }

    public static List<Double> doubleMeanMethod(double money, int number) {
        if (money < 0 && number < 1) {
            return null;
        }
        List<Double> result = new ArrayList<>();
        double amount, sum = 0;
        int remainingNumber = number;
        int i = 1;
        while (remainingNumber > 1) {
            amount = nextDouble(0.01, 2 * (money / remainingNumber));
            sum += amount;
            System.out.println("第" + i + "个人领取的红包金额为：" + format(amount));
            money -= amount;
            remainingNumber--;
            result.add(amount);
            i++;
        }
        result.add(money);
        System.out.println("第" + i + "个人领取的红包金额为：" + format(money));
        sum += money;
        System.out.println("验证发出的红包总金额为：" + format(sum));
        return result;
    }

    public static double nextDouble(final double min, final double max) {
        return min + ((max - min) * new Random().nextDouble());
    }

    public static String format(double value) {
        return new java.text.DecimalFormat("0.00").format(value);
    }
}
